using System;
using MSOffice = Microsoft.Office.Core;

namespace Office.Utility.Toolbar
{
    public sealed class ToolboxTextBox : ToolbarControl
	{
		public ToolboxTextBox(string id)
			: base(id)
		{
		}

		public ToolboxTextBox(string id, string caption)
			: base(id, caption)
		{
		}

		public ToolboxTextBox(string id, string caption, string tooltip)
			: base(id, caption, tooltip)
		{
		}

		internal override void Attach(MSOffice.CommandBar bar, WindowAdapter window)
		{
			var tbx = FindControl<MSOffice.CommandBarControl>(bar);

			if (tbx == null)
			{
				tbx = bar.Controls.Add(
				    MSOffice.MsoControlType.msoControlEdit,
				    Type.Missing, Type.Missing,
				    Position != null ? Position.Value : Type.Missing, true);

				tbx.Parameter = Id;
				tbx.Tag = Guid.NewGuid().ToString();
			}

			tbx.Caption = Caption;
			tbx.TooltipText = ToolTip;

			AddControl(tbx);
			window.Close += ((sender, args) => RemoveControl(tbx));

		}

	}
}
